Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pixel shader effect cache #981

Open
wants to merge 13 commits into
base: uwp/main
Choose a base branch
from

Conversation

benstevens48
Copy link

Closes #969 and implements the API from there, namely

static void PixelShaderEffect.RegisterEffect(UInt8[] shaderCode, Guid id, Int32 maxSamplerOffset, SamplerCoordinateMapping[] coordinateMappings, EffectBorderMode[] borderModes, CanvasImageInterpolation[] sourceInterpolations);
static PixelShaderEffect PixelShaderEffect.CreateEffect(Guid id);
static PixelShaderEffect PixelShaderEffect.RegisterAndCreateEffect(UInt8[] shaderCode, Guid id, Int32 maxSamplerOffset, SamplerCoordinateMapping[] coordinateMappings, EffectBorderMode[] borderModes, CanvasImageInterpolation[] sourceInterpolations);
static Boolean PixelShaderEffect.IsEffectRegistered(Guid id);
static void PixelShaderEffect.UnregisterEffect(Guid id);

Please look at the overall diff rather than the individual commits as I refactored it a bit.

I realize you may not want to merge this, but this is now in my forked version, so I thought I'd post it here anyway. There aren't actually that many changes. The main change to the existing code was replacing ShaderDescription as a direct member of SharedShader state with a shader_ptr instead.

The absolute time savings aren't massive but I think it's still worth it as my app may load 1000s of images as quickly as possible. I tested creating an instance of PixelShaderEffect (without realizing it) using some shader code which is not too complicated but does have a few constants. I found that on average, without the new caching code, it took 0.15ms to create each instance, whereas after registration, using the new code, it took 0.002ms to create each instance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant